/**
 * 
 */
package leetCode;

/**
 * @author zhongfang
 *
 */
public class Dota2Senate {
	public String predictPartyVictory(String senate) {
		int DCount = 0, RCount = 0;
		boolean[] haveRight = new boolean[senate.length()];
		for (int i = 0; i < senate.length(); i++) {
			if (senate.charAt(i) == 'R') {
				RCount++;
			} else {
				DCount++;
			}
			haveRight[i] = true;
		}
		int DBanedCount = 0;
		int RBanedCount = 0;
		if (RCount == 0) {
			return "Dire";
		}
		if (DCount == 0) {
			return "Radiant";
		}
		while (true) {
			for (int i = 0; i < senate.length(); i++) {
				if (haveRight[i] == false) {
					continue;
				}
				if (senate.charAt(i) == 'R') {
					// 检查是否有效
					if (RBanedCount == 0) {// 可以去禁止另一个
						DBanedCount++;
					} else {
						haveRight[i] = false;
						RBanedCount--;
						RCount--;// 存活的人减少
						if (RCount == 0) {
							return "Dire";
						}
					}
				} else {
					if (DBanedCount == 0) {// 可以去禁止另一个
						RBanedCount++;
					} else {
						haveRight[i] = false;
						DBanedCount--;
						DCount--;// 存活的人减少

						if (DCount == 0) {
							return "Radiant";
						}
					}
				}
			}
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Dota2Senate dota2Senate = new Dota2Senate();
		System.out.println(dota2Senate.predictPartyVictory("RD"));
	}

}
